//
// Created by user on 2022/3/15.
//
#include <iostream>
using namespace std;

struct ListNode {
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
    };

ListNode* deleteDuplicates(ListNode* head) {
    if(head== nullptr || head->next== nullptr)return head;

    ListNode * prev = head;
    ListNode *curr = head->next;
    while (curr!= nullptr){
        //相同情况
        if(curr->val == prev->val){
            prev->next = curr->next;
            curr = nullptr;
        }else{
            prev = curr;
        }
        curr = prev->next;
    }
    return head;
}